package cn.microservices.cloud.gateway.interpector.ip;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Ip的黑名单
 */
@Component
public class IpBlackList  {

	public final Map<String, String> IP_BLACKLIST = new ConcurrentHashMap<>();
	private Logger log = LoggerFactory.getLogger(getClass());


	/**
	 * 设置Ip黑名单
	 *
	 * @param ip
	 */
	public void addIpBlack(String ip) {

		if (StringUtils.isEmpty(ip)) {
			log.warn("设置黑名单所传Ip为空");
			return;

		}
		//设定初始值
		IP_BLACKLIST.put(ip, ip);

	}

	/**
	 * 删除Ip黑名单
	 *
	 * @param ip
	 */
	public void delIpBlack(String ip) {

		if (StringUtils.isEmpty(ip)) {
			log.warn("删除黑名单所传Ip为空");
			return;

		}
		//设定初始值
		IP_BLACKLIST.remove(ip);

	}


}
